import echarts from 'echarts';

interface IConfig {
  dataX?: Array<string>,
  nameX?: string,
  nameY?: string,
  dataY?: Array<number>,
  ref: any,
  title?: string,
  color?: Array<any>,
  legendData?: Array<any>,
  seriesData?: Array<any>,
  xAxisData?: Array<any>
}

export function SingleElectricityLine(config: IConfig) {
  if(config.ref) {
    let myChart = echarts.init(config.ref);
    let option = {
      title: {
        text: config.title,
      },
      color: config.color,
      tooltip: {
        trigger: 'axis'
      },
      legend: {
        data: config.legendData
      },
      grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
      },
      toolbox: {
        feature: {
          saveAsImage: {}
        }
      },
      xAxis: {
        type: 'category',
        min: 'dataMin',
        boundaryGap: false,
        data: config.xAxisData
      },
      yAxis: {
        type: 'value'
      },
      series: config.seriesData
    };
    myChart.setOption(option)
  }
}

